import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import operate from '@dfeidao/atom-nodejs/db/operate';
import { systemid, productid } from '../../atom/config';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import { SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS } from 'constants';

interface Message {
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
	data: {
		value_no: string;
		optional_value: string;
		value_description: string;
		proprity: number,
	};

}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:e:\feidao\KaoHe\kh\src\basic-data-wzz\zj-000003\s001,action_id:' + action_id);

	const res = await doc_code(action_id, session_id, systemid, 'BM0014272', '', 1);
	// 插入数据
	const { exec, insert } = operate(action_id, session_id, systemid);
	insert('property_optional_values', { productid, value_no: message.data.value_no, optional_value_no: res.result, optional_value: message.data.optional_value, value_description: message.data.value_description, priority: message.data.proprity });
	const res1 = await exec();

	log('Service end path:e:\feidao\KaoHe\kh\src\basic-data-wzz\zj-000003\s001,action_id:' + action_id);
	return {
		data: res1
	};
}
